import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

import directive from '@/directive'
// 全局插槽
import libjs from '@/components/libs'
Vue.use(libjs)
// 全局过滤器
import filters from '@/filters/index.js'
Vue.use(filters)

Vue.use(directive)
Vue.prototype.$bus = new Vue()
// 全局自定义
// 第一种方法
// Vue.directive('指令名',{'生命周期'})
// for (const key in directive) {
//   Vue.directive(key, directive[key])
// }

// 第二种
// obj:{a;1,b:2} Object.keys(对象)====[对象1,对象2] ====>Object.keys(obj) ===['a','b']
// Object.keys(directive).forEach((item) => {
//   Vue.directive(item, directive[item])
// })

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)
// 自定义全局指令
// Vue.directive('imagerror', {
//   inserted(dom, obj, vnode) {
//     // 只执行一次
//     obj.value = obj.value || require('@/assets/common/bigUserHeader.png')
//     dom.src = dom.src || obj.value
//     dom.onerror = () => {
//       dom.src = obj.value
//     }
//   },
//   // 更新时触发
//   componentUpdate(dom, obj, vnode) {
//     obj.value = obj.value || require('@/assets/common/bigUserHeader.png')
//     dom.src = dom.src || obj.value
//   },
//   // 销毁
//   unbind(dom) {
//     dom.src = null
//   }
// })

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: (h) => h(App)
})
